from django.db import models
# Create your models here.
class Problem(models.Model):
    '''
    This model represents a problem in the system
    but here is the judger end, so we only need the Problem ID ,the configuration folder path and the
    problem type.
    '''
    problem_id = models.TextField(primary_key=True)
    config_path = models.TextField()
    problem_type = models.TextField() # we'd better not make it a TextChoices field
    def __str__(self):
        return f"Problem {self.problem_id} of type {self.problem_type} at {self.config_path}"
    class Meta:
        db_table = 'problems'

class Record(models.Model):
    '''
    This model represents a submission record in the system.
    We need Problem Id,record id, submission time, status, score, running time/memory and 
    the detailed result json.
    Our system is distributed, so we may only have part of the records here, so we
    cannot use AutoField for record_id.
    '''
    record_id = models.BigIntegerField(primary_key=True)
    problem = models.ForeignKey(Problem,on_delete=models.CASCADE)
    submit_time = models.DateTimeField()
    status = models.TextField() # keep sync with definitions in soj-core
    score = models.FloatField()
    time_used = models.IntegerField() # in milliseconds
    memory_used = models.IntegerField() # in kilobytes
    detail_json = models.JSONField()
    def __str__(self):
        return f"Record {self.record_id} for Problem {self.problem.problem_id} : status {self.status}, score {self.score}, time {self.time_used} ms, memory {self.memory_used} KB"
    class Meta:
        db_table = 'records'
